﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;

public partial class Admin_ViewContact : System.Web.UI.Page
{
    ContactController contactController = new ContactController();
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            
            if (!string.IsNullOrWhiteSpace(Request.QueryString["id"]))
            {
                int id = Convert.ToInt32(Request.QueryString["id"]);
                DataTable dt = contactController.GetByID(id);
                Contact c = new Contact(dt.Rows[0]);
                txtSender.Text = c.Name;
                txtEmail.Text = c.Email;
                txtTitle.Text = c.Title;
                txtContent.Text = c.Content;
                lblTime.Text = c.DateStart.ToString("yyyy-MM-dd");
            }
        }
    }
    [WebMethod]
    public static string sendMail()
    {
        return "";
    }
    protected void btnSendMail_Click(object sender, EventArgs e)
    {
        string email = txtEmail.Text;
        string title = txtTitle.Text;
        string content = txtFeedback.Text;
        SendMail sm = new SendMail();
        sm.Content = content;
        sm.Title = title;
        sm.DisplayName = "Hoàng Hà Mobile";
        sm.IsHtml = true;
        sm.IsSSL = true;
        sm.To = email;
        sm.Subject = "Reply: " + title;
        sm.Templatefile = Server.MapPath("~/Admin/Contact.htm");
        sm.SendEMail();
    }
}